home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 23
/
CU Amiga - Super CD-ROM 23 (June 1998).iso
/
CUCD
/
Magazine
/
C_Tutorial
/
Part-10
/
frac0
/
fractal.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-03-02
|
1KB
|
47 lines
#include "fractal.h"
#include "gadgets.h"
#include<clib/graphics_protos.h>
static int calc(float, float, int);
/* Draw a fractal in the window */
void drawFractal(struct Window* win)
{
/* The width, height and number of colours for drawing */
int w=win->Width, h=win->Height, d=1<<win->WScreen->BitMap.Depth;
/* The snapshot of the mandelbrot set to draw */
/* (Adjust these numbers to draw different fractals) */
float width=4.0, height=4.0, top=-2.0, left=-2.5;
int x;
for(x=0; x<w; x++)
{
int y;
for(y=0; y<h; y++)
{
/* Set the current colour */
setFgPen(win, calc(x*width/w+left,y*height/h+top,d));
/* Draw the pixel */
WritePixel(win->RPort,x,y);
}
}
}
/* Calculate the colour of a particular point */
/* (This is the number of iterations of the equation */
/* needed to exceed the bound value) */
static int calc(float x, float y, int d)
{
float xc=x, yc=y;
int it;
/* Adjust the 16.0 to give different colour spreads */
for(it=0; it<d && (xc*xc)+(yc*yc)<16.0; it++)
{
float oldx = xc;
xc = oldx*oldx-yc*yc+x;
yc = 2.0*oldx*yc+y;
}
return it;
}